package com.JavaBasic;

import java.util.Calendar;

public class CalendarDemo {
	public static void main(String[] args) {
		// Calendar是抽象方法，不能创建对象，只能通过静态方法获取内部的子类对象
		Calendar calendar = Calendar.getInstance();
		
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR);
		int minute = calendar.get(Calendar.MINUTE);
		int second = calendar.get(Calendar.SECOND);
		System.out.println("获取到年:" + year);
		System.out.println("月:" + month);
		System.out.println("日:" + day);
		System.out.println("时:" + hour);
		System.out.println("分:" + minute);
		System.out.println("秒:" + second);
		
		// 年份加1
		calendar.add(Calendar.YEAR, 1);
		System.out.println("年份加1:" + calendar.get(Calendar.YEAR) + "年");
		
		// 设置时间为2008年8月8日
		calendar.set(2008, 7, 8);
		System.out.println("设置以后的时间是:" + calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONDAY) + 1) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日");
	}
}
